import 'package:flutter/material.dart';

import 'package:sqflite/sqflite.dart' as sql;
// import 'package：path/path.dart';

/**
 * sqlite3 使用
 */
class SqliteDemo extends StatefulWidget {
  const SqliteDemo({super.key});

  @override
  State<SqliteDemo> createState() => _SqliteDemoState();
}

class _SqliteDemoState extends State<SqliteDemo> {
  ///获取db对象，异步函数
  Future<sql.Database> getdb() async {
    ///语句是异步执行的需添加await()
    return await sql.openDatabase('sql.getDatabasesPath(),');
  }

  ///创建一个表格
  void createTable() async {
    var db = await getdb();
    db.execute("""create table IF NOT EXISTS record2(
              id INTEGER PRIMARY KEY AUTOINCREMENT, 
              money TEXT,date1 TEXT)
    """);
  }

  ///

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('sqlite demo'),
        centerTitle: true,
      ),
      body: Column(
        children: [
          ElevatedButton(onPressed: () {}, child: Text('创建表格')),
          ElevatedButton(onPressed: () {}, child: Text('插入数据')),
          ElevatedButton(onPressed: () {}, child: Text('显示所有数据')),
        ],
      ),
    );
  }
}
